package com.study.app.net

import okhttp3.Interceptor
import okhttp3.Response
import java.security.MessageDigest

class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val newBuilder = chain.request().newBuilder()
        newBuilder.apply {
//            addHeader("platform", platform)
//            addHeader("authorization", getToken())
//            addHeader("datetime", dataTime.toString())
//            addHeader("encryption", encryption)
        }

        return chain.proceed(newBuilder.build())
    }

    private fun encrypt(dataStr: String): String {
        try {
            val m = MessageDigest.getInstance("MD5")
            m.update(dataStr.toByteArray(charset("UTF8")))
            val s = m.digest()
            var result = ""
            for (i in s.indices) {
                result += Integer.toHexString(0x000000FF and s[i].toInt() or -0x100).substring(6)
            }
            return result
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return ""
    }
}